$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
    //上部分全部属性
    var device=new Object();
    device.id=$("#id").val();
    device.deviceSn=$("#deviceSn").val();
    device.deviceType=$("#deviceType").val();
    device.remarks=$("#remarks").val();
    device.deviceState=$("#deviceState").val();
    device.locationId=$("#locationId").val();
    device.behaviorType=$("#behaviorType").val();
    var box=$("#proBox").find(" select");
    //绑定的全部属性
    var jsonArry=new Array();
    for(var i=0;i<box.length;i++){
        var json=new Object();
        if ($(box[i]).val()!=""){
            json.bindingType=$(box[i]).attr("name");
            json.deviceBindingId=$(box[i]).val();
            json.name=$(box[i]).find("option:selected").text();
            jsonArry.push(json);
        }
    }
    device.binding=jsonArry;
	$.ajax({
        type : "POST",
        contentType: "application/json;charset=utf-8",
		url : "/equipment/deviceExample/update",
		data : JSON.stringify(device),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("更新成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            deviceType : {
                required : true
            },deviceState : {
                required : true
            },behaviorType : {
                required : true
            }
		},
		messages : {
            deviceType : {
                required : icon + "请选择"
            }, deviceState : {
                required : icon + "请选择"
            }, behaviorType : {
                required : icon + "请选择"
            }
		}
	})
}